package com.gxa.controller.shezhicontroller;

import com.gxa.common.R;
import com.gxa.pojo.GongYingShangType;
import com.gxa.pojo.ShangPinType;
import com.gxa.service.shezhiservice.KeHuType46Service;
import com.gxa.service.shezhiservice.ShangPinType46Service;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * @Author x
 */
@RestController
@RequestMapping("/ShangPinType")
@Api(value = "商品类别管理" , tags = "商品类别数据接口API")
@RequiresPermissions("商品类别")
public class ShangPinTypeController {

    @Autowired(required = false)
    public R r;

    @Autowired(required = false)
    public ShangPinType46Service shangPinType46Service;

    @GetMapping("/selectAllShangPinTypeForPage")
    @ApiOperation(value = "商品查询接口" ,notes = "提供当前页码数与每页显示条数",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })

    public R selectAllShangPinTypeForPage(@RequestParam int page,@RequestParam int size)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        ArrayList<Object> list = new ArrayList<>();
//        list.add("jjj");
//        r.setData(list);
//        return r;
        return shangPinType46Service.selectAllShangPinTypeForPage(page , size );
    }
    @GetMapping("/selectShangPinTypeByType")
    @ApiOperation(value = "商品查询接口（根据条件查询）",notes="提供当前页码与每页显示条数，商品类别",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示条数", required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "shangPinType",value = "商品类别",required = false,dataType = "int",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectShangPinTypeByType(@RequestParam int page,@RequestParam int size,String shangPinType)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        ArrayList<Object> list = new ArrayList<>();
//        ShangPinType shangPinType = new ShangPinType();
//        shangPinType.setShangPinType("66");
//        list.add(shangPinType);
//        r.setData(list);
//        return r;

        return shangPinType46Service.selectShangPinTypeByType(page , size, shangPinType );
    }
   @PostMapping("/insertShangPinType")
    @ApiOperation(value = "新增商品接口",notes="提供商品信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertShangPinType(@RequestBody ShangPinType shangPin)
    {
//        r.setCode(200);
//        r.setMsg("查询成功！");
//        ArrayList<Object> list = new ArrayList<>();
//        ShangPinType shangPinType = new ShangPinType();
//        shangPinType.setShangPinType("663");
//        list.add(shangPinType);
//        r.setData(list);
//        return r;
        return shangPinType46Service.insertShangPinType(shangPin);
    }

    @PostMapping("/updateShangPinTypeById")
    @ApiOperation(value = "修改商品信息接口",notes="提供商品信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateShangPinTypeById(@RequestBody ShangPinType shangPin)
    {
//        r.setCode(200);
//        r.setMsg("修改成功！");
//        ArrayList<Object> list = new ArrayList<>();
//        ShangPinType shangPinType2 = new ShangPinType();
//        shangPinType2.setShangPinType("66");
//        list.add(shangPinType2);
//        r.setData(list);
//        return r;
        return shangPinType46Service.updateShangPinTypeById(shangPin);
    }

    @PostMapping("/deleteShangPinTypeById")
    @ApiOperation(value = "删除商品接口",notes = "提供商品id",httpMethod = "post",response = R.class)
    @ApiImplicitParam(name="id",value = "主键",required = true,dataType = "int")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteShangPinTypeById(@RequestParam int id)
    {
//        r.setCode(200);
//        r.setMsg("删除成功！");
//        ArrayList<Object> list = new ArrayList<>();
//        ShangPinType shangPinType3 = new ShangPinType();
//        shangPinType3.setId(5);
//        list.add(shangPinType3);
//        r.setData(list);
//        return r;
        return shangPinType46Service.deleteShangPinTypeById(id);
    }




}
